package com.liu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.mapper.BmsCommentMapper;
import com.liu.model.dto.CommentDTO;
import com.liu.model.entity.BmsComment;
import com.liu.model.entity.UmsUser;
import com.liu.model.vo.CommentVO;
import com.liu.service.IBmsCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author liumiao
 * @create 2021-10-21-17:50
 */

@Slf4j
@Repository
public class IBmsCommentServiceImpl extends ServiceImpl<BmsCommentMapper, BmsComment> implements IBmsCommentService {
   /*查看评论*/
    @Override
    public List<CommentVO> getCommentsByTopicID(String topicid) {
        List<CommentVO> listBmsComment = new ArrayList<>();
        try {
            listBmsComment = this.baseMapper.getCommentsByTopicID(topicid);
        }catch (Exception e){
            log.info("listBmsComment失败");
        }
        return listBmsComment;
    }


    /*添加评论*/
    @Override
    public BmsComment create(CommentDTO dto, UmsUser user) {
        BmsComment comment = BmsComment.builder()
                .userId(user.getId())
                .content(dto.getContent())
                .topicId(dto.getTopic_id())
                .createTime(new Date())
                .build();
         this.baseMapper.insert(comment);
        return comment;
    }
}
